<?php
/**
 * Author:xsc
 * Time:2023/10/12 16:46
 */

namespace App\Repository;

use  App\Models\OpenPlatformRoute;

class OpenPlatformRouteRepo extends BaseRepo
{

    /**
     * 查询平台是否有某个路由的权限
     * @param int $platform_id
     * @param string $route_name
     * @return array
     * Author:xsc
     * Time:2023/10/16 16:23
     */
    public function checkRoute(int $platform_id, string $route_name)
    {
        $fields = ['pr.*', 'r.name', 'r.route'];
        $where = [
            ['pr.platform_id', '=', $platform_id],
            ['pr.is_cancel', '=', 0],
            ['r.route', '=', $route_name],
        ];
        $res = OpenPlatformRoute::query()
            ->from('open_platform_route', 'pr')
            ->join('open_route as r', 'pr.route_id', '=', 'r.id')
            ->where($where)
            ->first($fields);
        return $res ? $res->toArray() : [];
    }

}
